<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<%@ page pageEncoding="UTF-8" %>

<%@ page import="jp.co.technotree.apl.api.common.Message,jp.co.technotree.common.ApplicationManager" %>
<%@ page import="jp.co.technotree.apl.cmd.spare.Spa2000Bean,jp.co.technotree.apl.api.common.GlobalConst" %>
<%@ include file="../common/common.jsp"%>
<jsp:useBean id="formBean" class="jp.co.technotree.apl.cmd.spare.Spa2000Bean" scope="request" />
<%
	ApplicationManager appMng = ApplicationManager.getInstance();	//アプリケーションマネージャの取得（パス等）
	//画像キャッシュ対策
	java.util.Date nowDate = new java.util.Date();
	java.sql.Timestamp imageTime = new java.sql.Timestamp(nowDate.getTime());
	
	String strDisplayCate = formBean.getDisplayCate();	// inv3100=直結看板仮品番モード
	String strOutputCate = formBean.getOutputCate();	//1=新規モード 2=直結看板変更モード
	
	
%>
<html>
	<head>
		<title>予備品管理システム - 直結看板予備品情報メンテナンス画面</title>
		<link rel="SHORTCUT ICON" href="../common/img/default/sys_icon.ico">

		<link rel='stylesheet' type='text/css' href='../../common/css/common/base.css' >
		<link rel='stylesheet' type='text/css' href='../../common/css/common/common.css'>
		<link rel='stylesheet' type='text/css' href='../../common/css/spare/spa5000.css'>

		<script language="javascript" src="../../common/js/base.js"></script>
		<script language="javascript" src="../../common/js/menu/topmenu.js"></script>

		<!-- ITEM-DROPDOWN START -->
		<link rel="stylesheet" href="../../common/js/dropdown/dropdown.css" type="text/css">
		<script src="../../common/js/dropdown/dropdown.js" type="text/javascript"></script>
		<!-- ITEM-DROPDOWN END -->

		<!--ポップアップ用-->
		<link rel='stylesheet' type='text/css' href='../../common/css/popUpPc.css' >
		<script type='text/javascript' src='../../common/js/popUpPc.js'></script>
		
		<!-- システムログ -->
		<script src="../../common/js/systemlog.js"></script>

			<style type='text/css'>
				.LinkItem {
					cursor: pointer;
				}
				.div-wid {
					border-bottom:solid 1px #ccc;
					width:1130px; /* 横幅合計 + スクロールバー分 */
					height:400px;
					overflow:auto;
				}
				.txtmode1 {
 					 ime-mode: active;   /* 全角モード */
				}
				.txtmode2 {
  					ime-mode: inactive; /* 半角モード */
				}
				.txtmode3 {
  					ime-mode: disabled; /* 半角のみモード */
				}
				.ReadStyle{
					 background-color:#CCC;
				}
			</style>

<script language="javascript">

var ITEMNM_MODEL_MAXLENGTH=100;

//画面固定
//document.addEventListener('touchmove', function (e) { e.preventDefault(); }, false);

function onInit(){
	//処理完了後、メッセーを出してメイン画面に遷移
	var stateFlg = "<%=formBean.getStateFlg()%>";
	
	var afterFunc="nextPageJump('spa1000');";
	if(stateFlg == "1"){
		//登録処理を正常に完了しました
		alert_Info2("<%=Message.getMessage("INF00030").replace("$1", "直結看板予備品情報")%>",afterFunc);
	}
	
	if(stateFlg == "2"){
		//変更処理を正常に完了しました
		alert_Info2("<%=Message.getMessage("INF00040").replace("$1", "直結看板予備品情報")%>",afterFunc);
	}
	
	if(stateFlg == "3"){
		//直結看板以外予備品への移動登録処理を正常に完了しました
		alert_Info2("<%=Message.getMessage("INF00020").replace("$1", "直結看板以外予備品への移動登録処理")%>",afterFunc);
	}
	//削除にチェックが入ってる時の処理
	delDivChange();
	

	
	
	var imgpath = "<%=appMng.getAppConfig("userconfig.imagepath")%><%=formBean.getPicfileNm() %>";
	
	
	
	
	
	//-------------------------------------------------------------------------
	//<!-- RACKNO-DROPDOWN START -->
	var panel2 = document.getElementById("dropdown-panel2");
	var input2 = document.getElementById("addTable");
	var targetList2 = getElementsByClassName2(input2,"input","rackNo",true);
	dropdown2 = new CItemDropDownList(targetList2,panel2,"drop-contents2");
	dropdown2.setKeyUpEvent(text_onKeyUp2);
	dropdown2.setSelectEvent(list_onSelect2);
	dropdown2.serverURL="../rac1099/rac1099";
	
	//
	dropdown2.createTable=function(object,sender,json) {
		var itemList = this.itemList;
		var tableText = "<table cellspacing='0' cellpadding='0' border='0' id='"+this.tableName+"'>";
		if (itemList!=null && itemList.length!=0) {
			for ( var i=0; itemList && i<itemList.length; i++ ){
				var item = itemList[i];
				
				tableText+= "<tr>";
				tableText+= "<td>"+item.value1+"</td>";
				tableText+= "</tr>";
			}
		} else {
			tableText+= "<tr>";
			tableText+= "<td>該当なし</td>";
			tableText+= "</tr>";
			tableText+= "</table>";
		}
		tableText+= "</table>";
		
		var canvas = document.getElementById(this.canvasName);
		canvas.innerHTML=tableText;
	}
	//<!-- RACKNO-DROPDOWN END -->
	//-------------------------------------------------------------------------
	
	//-------------------------------------------------------------------------
	//<!-- 設備機番 START --> 
	var panel3 = document.getElementById("dropdown-panel3");
	
	var input3 = document.getElementById("addTable");
	var targetList3 = getElementsByClassName3(input3,"input","machineNo",true);
	dropdown3 = new CItemDropDownList(targetList3,panel3,"drop-contents3");
	dropdown3.setKeyUpEvent(text_onKeyUp3);
	dropdown3.setSelectEvent(list_onSelect3);
	dropdown3.serverURL="../sys1099/sys1099";
	
	dropdown3.createTable=function(object,sender,json) {
		var itemList = this.itemList;
		var tableText = "<table cellspacing='0' cellpadding='0' border='0' id='"+this.tableName+"'>";
		if (itemList!=null && itemList.length!=0) {
			for ( var i=0; itemList && i<itemList.length; i++ ){
				var item = itemList[i];
				
				tableText+= "<tr>";
				tableText+= "<td>"+item.value1+"</td>";
				tableText+= "</tr>";
			}
		} else {
			tableText+= "<tr>";
			tableText+= "<td>該当なし</td>";
			tableText+= "</tr>";
			tableText+= "</table>";
		}
		tableText+= "</table>";
		
		var canvas = document.getElementById(this.canvasName);
		canvas.innerHTML=tableText;
	}
	//-------------------------------------------------------------------------
}



function nextPageJump(nextPage){
	mainForm = document.getElementById("F1");
	document.getElementById("nextPage").value = nextPage;
	mainForm.submit();
}

//Y品番ハイフンを付ける
function itemNoKeyUp(obj){
	var value = obj.value;
	//-----------------------------------------------
	//品番自動ハイフン「-」を付ける
	var chkLen=5;
	if(event.keyCode != 0008){
		//指定の桁以上ならスタート
		if(value.length>=chkLen){
			var hikaku = value.substring(chkLen, chkLen+1);
			if(hikaku != "-"){
				var frontValue = value.substring(0, chkLen);
				var backValue  = value.substring(chkLen, value.length);
				obj.value=frontValue+"-"+backValue;
			}
		}
	}
	
	//小文字を大文字へ
	obj.value = obj.value.toUpperCase();
	value = obj.value;
	//-----------------------------------------------
}

//戻るボタン押下
function backBtn(nextPage){
	var changeFlg = changeCheck();
	if(changeFlg=="1"){
		//発注処理を中止します。よろしいですか？
		var afterFunc="nextPageJump('"+nextPage+"');";
		if (!confirm_Custom3("<%=Message.getMessage("INF01040").replace("$1", "直結看板予備品メンテナンス処理")%>",afterFunc)){
			return ;
		}
	}else{
		nextPageJump(nextPage);
	}
}

//編集を行ったかチェック
//return:0=変更なし 1=変更あり
function changeCheck() {
	var frm=document.main;
	var changeFlg = "0";
	
	//変更以外
	<%if(!"2".equals(strOutputCate)){ %>
		obj=frm["itemNo"]; if (obj.defaultValue != obj.value) {changeFlg="1";}
	<%} %>

	obj=frm["itemNm"]; if (obj.defaultValue != obj.value) {changeFlg="1";}
	obj=frm["model"]; if (obj.defaultValue != obj.value) {changeFlg="1";}
	obj=frm["unitPrice"]; if (obj.defaultValue != obj.value) {changeFlg="1";}
	obj=frm["leadTm"]; if (obj.defaultValue != obj.value) {changeFlg="1";}
	obj=frm["basicStock"]; if (obj.defaultValue != obj.value) {changeFlg="1";}
	obj=frm["odrLot"]; if (obj.defaultValue != obj.value) {changeFlg="1";}
	obj=frm["odrPoint"]; if (obj.defaultValue != obj.value) {changeFlg="1";}
	obj=frm["newStock"]; if (obj.defaultValue != obj.value) {changeFlg="1";}
	obj=frm["usedStock"]; if (obj.defaultValue != obj.value) {changeFlg="1";}
	obj=frm["upReason"]; if (obj.defaultValue != obj.value) {changeFlg="1";}
	obj=frm["rackNo"]; if (obj.defaultValue != obj.value) {changeFlg="1";}
	obj=frm["machineNo"]; if (obj.defaultValue != obj.value) {changeFlg="1";}
	//セレクトボックスのチェック
	//obj=frm["rackNo"]; if (obj.options[obj.selectedIndex].defaultSelected == false) {changeFlg="1";}
	obj=frm["cntDiv"]; if (obj.options[obj.selectedIndex].defaultSelected == false) {changeFlg="1";}
	//obj=frm["machineNo"]; if (obj.options[obj.selectedIndex].defaultSelected == false) {changeFlg="1";}
	obj=frm["supplier"]; if (obj.options[obj.selectedIndex].defaultSelected == false) {changeFlg="1";}
	obj=frm["partsMaker"]; if (obj.options[obj.selectedIndex].defaultSelected == false) {changeFlg="1";}
	return changeFlg;
}

//-------------------------------------------------------------------------
//<!-- ポップアップ START -->

//パップアップ解除
function back(){
	document.getElementById("opAlertBtn").style.display = "none";
	document.getElementById("opAlert").style.display = "none";
	document.getElementById("opAlertButton").style.display = "none";
	document.getElementById("opAlertTop").style.display = "none";
	document.getElementById("allbackgr").style.display = "none";
}

//<!-- ポップアップ END -->
//-------------------------------------------------------------------------

//-------------------------------------------------------------------------
//<!-- RACKNO-DROPDOWN START -->
var dropdown2 = null;

var inputDateTime2 = null;
var timerId2 = null;
var eventSrc2={};
function text_onKeyUp2(object,sender,evt){
	
	document.getElementById("rackNo").value = "";   //キーを削除
	
	var value = sender.value;
	eventSrc2.object = object;
	eventSrc2.sender = sender;
	eventSrc2.evt = evt;
	inputDateTime2 = new Date();
	//-----------------------------------------------
	//品番自動ハイフン「-」を付ける
	var chkLen=2;
	if(event.keyCode != 0008){
		//指定の桁以上ならスタート
		if(value.length>=chkLen){
			var hikaku = value.substring(chkLen, chkLen+1);
			if(hikaku != "-"){
				var frontValue = value.substring(0, chkLen);
				var backValue  = value.substring(chkLen, value.length);
				sender.value=frontValue+"-"+backValue;
			}
		}
	}
	//品番自動ハイフン「-」を付ける
	var chkLen=5;
	if(event.keyCode != 0008){
		//指定の桁以上ならスタート
		if(value.length>=chkLen){
			var hikaku = value.substring(chkLen, chkLen+1);
			if(hikaku != "-"){
				var frontValue = value.substring(0, chkLen);
				var backValue  = value.substring(chkLen, value.length);
				sender.value=frontValue+"-"+backValue;
			}
		}
	}
	//小文字を大文字へ
	sender.value = sender.value.toUpperCase();
	value = sender.value;
	//-----------------------------------------------
	if ( value.length >= <%=formBean.getTanaKensu() %> ){
		if ( evt.keyCode == 37 || evt.keyCode == 39 ){
			
		}else{
			if ( timerId2 == null ){
				// 連続送信防止
				timerId2 = window.setTimeout(function(){text_onTimeOut2(object,sender,evt);},500);
			}
		}
	}
}

/**
* 一定時間入力が止まった場合に動作
*/
function text_onTimeOut2(object,sender,evt){
	var nowDateTime = new Date();
	var lngTime = (nowDateTime.getTime()-inputDateTime2.getTime());
	if ( lngTime >= 1000 ){
		timerId2 = null;
		xmlRequest2(object,sender,evt);
	}else{
		timerId2 = window.setTimeout(function(){text_onTimeOut2(eventSrc2.object,eventSrc2.sender,eventSrc2.evt);},500);
	}
}

/**
* XML要求処理
*/
function xmlRequest2(object,sender,evt){
	//alert_Custom(evt.keyCode);
	var table = document.getElementById("drop-contents2");
	table.innerHTML="";
	
	var top = calculateOffsetTop(sender);
	var left = calculateOffsetLeft(sender);
	var height = sender.offsetHeight;
	var panel = document.getElementById("dropdown-panel2");
	panel.style.top=top+height+"px";
	panel.style.left=left+"px";
	panel.style.display="block";
	
	var param="sysId=<%=GlobalConst.TANA%>&"+"value1="+sender.value+"";
	
	try {
		var frm = document.main;
		var objs = frm["invCate"];
		if (objs[1].checked == true){
			//仮入出庫
			param += "&afterProc=1";
		}
	} catch (e) {
		
	}

	object.doXmlRequest(object,sender,param);
}


/**
* リスト選択時コールバック処理
*/
function list_onSelect2(object,sender,json){
	var panel = document.getElementById("dropdown-panel2");
	panel.style.display="none";
	sender.focus();
	
	//----------
	var name=sender.name;
	var idx=name.substring(name.indexOf("[")+1,name.length-1);
	
	document.getElementById("rackNo").value=json.valuecd;
	document.getElementById("rackNoTxt").value=json.value1;
	
}


function getElementsByClassName2(parent,tagName,className,fullMatch){
	var i=0,j=0;
	var result = [], cnt = 0;
	var list = parent.getElementsByTagName(tagName);
	for ( i=0; i<list.length; i++ ){
		var name = list[i].className;
		if ( name ){
			var nameList = name.split(' ');
			for ( j=0; j<nameList.length; j++ ){
				if ( fullMatch ){
					if ( nameList[j] == className ){
						result[cnt++] = list[i];
					}
				}else{
					if ( nameList[j].indexOf(className) != -1 ){
						result[cnt++] = list[i];
					}
				}
			}
		}
	}
	return result;
}
function closeBtn2(){
	var panel = document.getElementById("dropdown-panel2");
	panel.style.display="none";
} 
//----------------------------------------------------------------------

//-------------------------------------------------------------------------
//<!-- 設備機番-DROPDOWN START -->
var dropdown3 = null;

var inputDateTime3 = null;
var timerId3 = null;
var eventSrc3={};
function text_onKeyUp3(object,sender,evt){
	
	
	document.getElementById("machineNo").value = "";   //設備機番キーを削除
	
	var value = sender.value;
	eventSrc3.object = object;
	eventSrc3.sender = sender;
	eventSrc3.evt = evt;
	inputDateTime3 = new Date();
	//-----------------------------------------------

	//品番自動ハイフン「-」を付ける
	var chkLen=4;
	if(event.keyCode != 0008){
		//指定の桁以上ならスタート
		//if(value.length>=chkLen){
		//	var hikaku = value.substring(chkLen, chkLen+1);
		//	if(hikaku != "-"){
		//		var frontValue = value.substring(0, chkLen);
		//		var backValue  = value.substring(chkLen, value.length);
		//		sender.value=frontValue+"-"+backValue;
		//	}
		//}
	}
	//小文字を大文字へ
	sender.value = sender.value.toUpperCase();
	value = sender.value;
	//-----------------------------------------------
	if ( value.length >= 3 ){
		if ( evt.keyCode == 37 || evt.keyCode == 39 ){
			
		}else{
			if ( timerId3 == null ){
				// 連続送信防止
				timerId3 = window.setTimeout(function(){text_onTimeOut3(object,sender,evt);},500);
			}
		}
	}
}

/**
* 一定時間入力が止まった場合に動作
*/
function text_onTimeOut3(object,sender,evt){
	var nowDateTime = new Date();
	var lngTime = (nowDateTime.getTime()-inputDateTime3.getTime());
	if ( lngTime >= 1000 ){
		timerId3 = null;
		
		
		xmlRequest3(object,sender,evt);
	}else{
		timerId3 = window.setTimeout(function(){text_onTimeOut3(eventSrc3.object,eventSrc3.sender,eventSrc3.evt);},500);
	}
}

/**
* XML要求処理
*/
function xmlRequest3(object,sender,evt){
	//alert_Custom(evt.keyCode);
	var table = document.getElementById("drop-contents3");
	table.innerHTML="";
	
	var top = calculateOffsetTop(sender);
	var left = calculateOffsetLeft(sender);
	var height = sender.offsetHeight;
	var panel = document.getElementById("dropdown-panel3");
	panel.style.top=top+height+"px";
	panel.style.left=left+"px";
	panel.style.display="block";
	

	
	var param="sysId=<%=GlobalConst.SETBI_KIBAN%>&"+"value1="+sender.value+"";
	

	try {
		var frm = document.main;
		var objs = frm["invCate"];
		
		if (objs[1].checked == true){
			//仮入出庫
			param += "&afterProc=1";
		}
	} catch (e) {
		
	}

	object.doXmlRequest(object,sender,param);
}


/**
* リスト選択時コールバック処理
*/
function list_onSelect3(object,sender,json){
	var panel = document.getElementById("dropdown-panel3");
	panel.style.display="none";
	sender.focus();
	
	//----------
	var name=sender.name;
	var idx=name.substring(name.indexOf("[")+1,name.length-1);
	
	document.getElementById("machineNo").value=json.valuecd;
	document.getElementById("machineNoTxt").value=json.value1;
	
	
}


function getElementsByClassName3(parent,tagName,className,fullMatch){
	
	var i=0,j=0;
	var result = [], cnt = 0;
	var list = parent.getElementsByTagName(tagName);
	for ( i=0; i<list.length; i++ ){
		var name = list[i].className;
		if ( name ){
			var nameList = name.split(' ');
			for ( j=0; j<nameList.length; j++ ){
				if ( fullMatch ){
					if ( nameList[j] == className ){
						result[cnt++] = list[i];
					}
				}else{
					if ( nameList[j].indexOf(className) != -1 ){
						result[cnt++] = list[i];
					}
				}
			}
		}
	}
	return result;
}
function closeBtn3(){
	var panel = document.getElementById("dropdown-panel3");
	panel.style.display="none";
} 
//----------------------------------------------------------------------

//-------------------------------------------------------------------------
//<!-- 予備品区分変更の関数 START -->

//入力チェックによる背景色を付ける
function validCheck2(){

	var delDivObj  =  document.getElementById("delDiv");  		//削除フラグ
	var cntDiv = document.getElementById("cntDiv"); 			//カウント品可否
	var itemNm = document.getElementById("itemNm"); 			//品名
	var model = document.getElementById("model");				//型式
	var rackNo = document.getElementById("rackNo");			//棚番キー
	var rackNoTxt = document.getElementById("rackNoTxt");			//棚番
	var unitPrice  =  document.getElementById("unitPrice");  	//単価
	var leadTm  =  document.getElementById("leadTm");  		//リードタイム
	var machineNo = document.getElementById("machineNo");		//設備機番キー
	var machineNoTxt = document.getElementById("machineNoTxt");		//設備機番
	
	var basicStock  =  document.getElementById("basicStock");	//基準在庫
	var odrLot  =  document.getElementById("odrLot");  		//発注単位
	var odrPoint  =  document.getElementById("odrPoint");  	//発注点
	var newStock  =  document.getElementById("newStock");  	//新品在庫数
	var usedStock  =  document.getElementById("usedStock");  	//中古在庫数
	var upReason  =  document.getElementById("upReason");  	//変更理由
	
	//============
	//背景色解除
	//============
	//delDivObj.style.backgroundColor = 'white';
	cntDiv.style.backgroundColor = 'white';
	itemNm.style.backgroundColor = 'white';
	model.style.backgroundColor = 'white';
	rackNo.style.backgroundColor = 'white';
	rackNoTxt.style.backgroundColor = 'white';
	unitPrice.style.backgroundColor = 'white';
	leadTm.style.backgroundColor = 'white';
	machineNo.style.backgroundColor = 'white';
	machineNoTxt.style.backgroundColor = 'white';
	basicStock.style.backgroundColor = 'white';
	odrLot.style.backgroundColor = 'white';
	odrPoint.style.backgroundColor = 'white';
	newStock.style.backgroundColor = 'white';
	usedStock.style.backgroundColor = 'white';
	upReason.style.backgroundColor = 'white';
	if(delDivObj.checked){
		rackNo.style.backgroundColor = '#CCC';
		rackNoTxt.style.backgroundColor = '#CCC';
		newStock.style.backgroundColor = '#CCC';
		usedStock.style.backgroundColor = '#CCC';
	}
	//入力チェック（必須）-----------------------------------------------------------------start
	if(cntDiv.value ==""){
		cntDiv.style.backgroundColor = 'pink';
	}
	if(itemNm.value ==""){
		itemNm.style.backgroundColor = 'pink';
	}
	if(itemNm.value.length > ITEMNM_MODEL_MAXLENGTH){
		itemNm.style.backgroundColor = 'pink';
	}
	if(model.value ==""){
		model.style.backgroundColor = 'pink';
	}
	if(model.value.length > ITEMNM_MODEL_MAXLENGTH){
		model.style.backgroundColor = 'pink';
	}
	if(unitPrice.value ==""){
		unitPrice.style.backgroundColor = 'pink';
	}
	if(leadTm.value ==""){
		leadTm.style.backgroundColor = 'pink';
	}
	if(machineNo.value ==""){
		machineNo.style.backgroundColor = 'pink';
		machineNoTxt.style.backgroundColor = 'pink';
	}
	//入力チェック（必須）-----------------------------------------------------------------end
	//入力チェック-------------------------------------------------------------------------start
	
	if(unitPrice.value < 1){
		unitPrice.style.backgroundColor = 'pink';
	}
	if(leadTm.value < 0){
		leadTm.style.backgroundColor = 'pink';
	}
	if(basicStock.value < 0){
		basicStock.style.backgroundColor = 'pink';
	}
	if(odrLot.value < 0){
		odrLot.style.backgroundColor = 'pink';
	}
	if(odrPoint.value < 0){
		odrPoint.style.backgroundColor = 'pink';
	}
	
	var uploadFile = document.getElementById("uploadFile");
	
	uploadFile.style.backgroundColor = 'white';
	
	if(!fileCheck()){
		uploadFile.style.backgroundColor = 'pink';
	}
	//入力チェック-------------------------------------------------------------------------end
}
//「直結看板以外」実行
function itemChangeBtnExe(btnCate){
	mainForm = document.getElementById("F1");

	var itemNo ="";

	var delDivObj  =  document.getElementById("delDiv");  		//削除フラグ
	var cntDiv = document.getElementById("cntDiv").value; 			//カウント品可否
	var itemNm = document.getElementById("itemNm").value; 			//品名
	var model = document.getElementById("model").value;				//型式
	var rackNo = document.getElementById("rackNo").value;			//棚番
	var unitPrice  =  document.getElementById("unitPrice").value;  	//単価
	var leadTm  =  document.getElementById("leadTm").value;  		//リードタイム
	var machineNo = document.getElementById("machineNo").value;		//設備機番
	
	var basicStock  =  document.getElementById("basicStock").value;	//基準在庫
	var odrLot  =  document.getElementById("odrLot").value;  		//発注単位
	var odrPoint  =  document.getElementById("odrPoint").value;  	//発注点
	var newStock  =  document.getElementById("newStock").value;  	//新品在庫数
	var usedStock  =  document.getElementById("usedStock").value;  	//中古在庫数
	var upReason  =  document.getElementById("upReason").value;  	//変更理由
	
	
	//入力チェック-----------------------------------------------------------------start
	if(delDivObj.checked){
		alert_Custom("<%=Message.getMessage("WRN00140")%>");
		return ;
	}
	if(cntDiv ==""){
		alert_Custom("<%=Message.getMessage("WRN00010").replace("$1", "カウント可否")%>");
		return ;
	}else if(itemNm ==""){
		alert_Custom("<%=Message.getMessage("WRN00010").replace("$1", "品名")%>");
		return ;
	}else if(itemNm.length > ITEMNM_MODEL_MAXLENGTH){
		alert_Custom("<%=Message.getMessage("WRN01580").replace("$1", "品名").replace("$2","100")%>");
		return ;
	}else if(model ==""){
		alert_Custom("<%=Message.getMessage("WRN00010").replace("$1", "型式")%>");
		return ;
	}else if(model.length > ITEMNM_MODEL_MAXLENGTH){
		alert_Custom("<%=Message.getMessage("WRN01580").replace("$1", "型式").replace("$2","100")%>");
		return ;
	}
	
	if(machineNo ==""){
		alert_Custom("<%=Message.getMessage("WRN00010").replace("$1", "設備機番")%>");
		return ;
	}
	if(!fileCheck()){
		alert_Custom("<%=Message.getMessage("WRN01590").replace("$1", "画像ファイル").replace("$2","jpg,png,gif")%>");
		return ;
	}
	if(unitPrice ==""){
		alert_Custom("<%=Message.getMessage("WRN00010").replace("$1", "単価")%>");
		return ;
	}else if(unitPrice < 1){
		alert_Custom("<%=Message.getMessage("WRN00061").replace("$1", "単価")%>");
		return ;
	}else if(leadTm ==""){
		alert_Custom("<%=Message.getMessage("WRN00010").replace("$1", "L/T")%>");
		return ;
	}else if(leadTm < 0){
		alert_Custom("<%=Message.getMessage("WRN00060").replace("$1", "L/T")%>");
		return ;
	}
	if(basicStock < 0){
		alert_Custom("<%=Message.getMessage("WRN00060").replace("$1", "基準在庫")%>");
		return ;
	}
	if(odrLot < 0){
		alert_Custom("<%=Message.getMessage("WRN00060").replace("$1", "発注単位")%>");
		return ;
	}
	if(odrPoint < 0){
		alert_Custom("<%=Message.getMessage("WRN00060").replace("$1", "発注点")%>");
		return ;
	}
	//入力チェック-----------------------------------------------------------------end
	mRsvSupplyCheckZaiko(btnCate);
}

//「はい」を押された時
function yesItemChangeBtn(){
	document.getElementById("itemChangeExe").value = "1";
	document.getElementById("updateExe").value = "1";
	mainForm = document.getElementById("F1");
	mainForm.submit();
}

//「はい」を押された時
function yesItemChangeBtn2(btnCate){
	var afterFunc="yesItemChangeBtn('"+btnCate+"');";
	if (!confirm_Custom3("<%=Message.getMessage("INF01170").replace("$1","直結看板以外予備品情報")%>",afterFunc)){
		return ;
	}
}

//「予備品区分変更」ボタン押下
function itemChangeBtn(){
	
	validCheck2();//入力チェックによる背景色を付ける
	
	//順番メモ
	//１：mRsvSupplyCheckDelete
	//２：updateDtCheck
	//３：orderBtnExe
	mRsvSupplyCheckDelete("3");

}

//<!--  予備品区分変更の関数 END -->
//-------------------------------------------------------------------------

//「登録」ボタン押下
function orderBtn(){
	
	validCheck("1");//入力チェックによる背景色を付ける
	
	//順番メモ
	//１：orderBtnExe
	orderBtnExe("1");

}

//「変更」ボタン押下
function updateBtn(){

	validCheck("2");//入力チェックによる背景色を付ける
	
	var delDivObj  =  document.getElementById("delDiv");  		//削除フラグ
	
	//削除がクリックされていれば追加チェック
	if(delDivObj.checked){
		//順番メモ
		//１：mRsvSupplyCheckDelete
		//２：updateDtCheck
		//３：orderBtnExe
		mRsvSupplyCheckDelete("2");
	}else{
		//順番メモ
		//１：updateDtCheck
		//２：orderBtnExe
		updateDtCheck("2");
	}

}

//入力チェックによる背景色を付ける
function validCheck(btnCate){

	//変更以外
	<%if(!"2".equals(strOutputCate)){ %>
		var itemNo = document.getElementById("itemNo"); 		
		//============
		//背景色解除
		//============
		itemNo.style.backgroundColor = 'white';
		
		//============
		//背景色設定
		//============
		if(itemNo.value =="" && btnCate !="2"){
			itemNo.style.backgroundColor = 'pink';
		}
		if(!itemNo.value.match(/^Y[0-9]{4}-[0-9]{5}$/) && btnCate !="2"){
			itemNo.style.backgroundColor = 'pink';
		}
		
		//新規時のみ
		if(btnCate =="1"){
			//予備品Mから存在チェック
			if(!mRsvSupplyCheck(btnCate)){
				itemNo.style.backgroundColor = 'pink';
			}
		}
	<%}%>


	var delDivObj  =  document.getElementById("delDiv");  		//削除フラグ
	var cntDiv = document.getElementById("cntDiv"); 			//カウント品可否
	var itemNm = document.getElementById("itemNm"); 			//品名
	var model = document.getElementById("model");				//型式
	var rackNo = document.getElementById("rackNo");			//棚番キー
	var rackNoTxt = document.getElementById("rackNoTxt");			//棚番
	var unitPrice  =  document.getElementById("unitPrice");  	//単価
	var leadTm  =  document.getElementById("leadTm");  		//リードタイム
	var machineNo = document.getElementById("machineNo");		//設備機番キー
	var machineNoTxt = document.getElementById("machineNoTxt");		//設備機番
	
	var basicStock  =  document.getElementById("basicStock");	//基準在庫
	var odrLot  =  document.getElementById("odrLot");  		//発注単位
	var odrPoint  =  document.getElementById("odrPoint");  	//発注点
	var newStock  =  document.getElementById("newStock");  	//新品在庫数
	var usedStock  =  document.getElementById("usedStock");  	//中古在庫数
	var upReason  =  document.getElementById("upReason");  	//変更理由
	
	//============
	//背景色解除
	//============
	//delDivObj.style.backgroundColor = 'white';
	cntDiv.style.backgroundColor = 'white';
	itemNm.style.backgroundColor = 'white';
	model.style.backgroundColor = 'white';
	rackNo.style.backgroundColor = 'white';
	rackNoTxt.style.backgroundColor = 'white';
	unitPrice.style.backgroundColor = 'white';
	leadTm.style.backgroundColor = 'white';
	machineNo.style.backgroundColor = 'white';
	machineNoTxt.style.backgroundColor = 'white';
	basicStock.style.backgroundColor = 'white';
	odrLot.style.backgroundColor = 'white';
	odrPoint.style.backgroundColor = 'white';
	newStock.style.backgroundColor = 'white';
	usedStock.style.backgroundColor = 'white';
	upReason.style.backgroundColor = 'white';
	if(delDivObj.checked){
		rackNo.style.backgroundColor = '#CCC';
		rackNoTxt.style.backgroundColor = '#CCC';
		newStock.style.backgroundColor = '#CCC';
		usedStock.style.backgroundColor = '#CCC';
	}
	//============
	//背景色設定
	//============
	//削除の時のみ
	//if(delDivObj.checked){
	//	var errMsg1="";
	//	if(rackNo !=""){
	//		errMsg1 += "[棚番]";
	//	}
	//	if(newStock !="" && newStock !="0"){
	//		errMsg1 += "[新品在庫]";
	//	}
	//	if(usedStock !="" && usedStock !="0"){
	//		errMsg1 += "[中古在庫]";
	//	}
	//	if(errMsg1 != ""){
	//		rackNo.style.backgroundColor = 'pink';
	//		newStock.style.backgroundColor = 'pink';
	//		usedStock.style.backgroundColor = 'pink';
	//	}
	//}
	//入力チェック（必須）-----------------------------------------------------------------start
	if(cntDiv.value ==""){
		cntDiv.style.backgroundColor = 'pink';
	}
	if(itemNm.value ==""){
		itemNm.style.backgroundColor = 'pink';
	}
	if(itemNm.value.length > ITEMNM_MODEL_MAXLENGTH){
		itemNm.style.backgroundColor = 'pink';
	}
	if(model.value ==""){
		model.style.backgroundColor = 'pink';
	}
	if(model.value.length > ITEMNM_MODEL_MAXLENGTH){
		model.style.backgroundColor = 'pink';
	}
	if(rackNo.value =="" && !delDivObj.checked){
		rackNoTxt.style.backgroundColor = 'pink';
		rackNo.style.backgroundColor = 'pink';
	}
	if(unitPrice.value ==""){
		unitPrice.style.backgroundColor = 'pink';
	}
	if(leadTm.value ==""){
		leadTm.style.backgroundColor = 'pink';
	}
	if(machineNo.value ==""){
		machineNo.style.backgroundColor = 'pink';
		machineNoTxt.style.backgroundColor = 'pink';
	}
	if(basicStock.value ==""){
		basicStock.style.backgroundColor = 'pink';
	}
	if(odrLot.value ==""){
		odrLot.style.backgroundColor = 'pink';
	}
	if(odrPoint.value ==""){
		odrPoint.style.backgroundColor = 'pink';
	}
	if(newStock.value =="" && !delDivObj.checked){
		newStock.style.backgroundColor = 'pink';
	}
	if(usedStock.value =="" && !delDivObj.checked){
		usedStock.style.backgroundColor = 'pink';
	}
	if(upReason.value ==""){
		upReason.style.backgroundColor = 'pink';
	}
	//入力チェック（必須）-----------------------------------------------------------------end
	//入力チェック-------------------------------------------------------------------------start
	
	if(rackNo.value !="" && !delDivObj.checked){
		//予備品Mから棚番の存在チェック
		if(!mRsvSupplyCheckRackNo(btnCate)){
			rackNoTxt.style.backgroundColor = 'pink';
			rackNo.style.backgroundColor = 'pink';
		}
	}
	
	if(delDivObj.checked <%if(!"inv3100".equals(strDisplayCate)){%>&& btnCate !="2"<%}%>){
		//delDivObj.style.backgroundColor = 'pink';
	}
	if(unitPrice.value < 1){
		unitPrice.style.backgroundColor = 'pink';
	}
	if(leadTm.value < 0){
		leadTm.style.backgroundColor = 'pink';
	}
	if(basicStock.value < 1){
		basicStock.style.backgroundColor = 'pink';
	}
	if(odrLot.value < 1){
		odrLot.style.backgroundColor = 'pink';
	}
	if(odrPoint.value < 0){
		odrPoint.style.backgroundColor = 'pink';
	}
	if(newStock.value < 0 && !delDivObj.checked){
		newStock.style.backgroundColor = 'pink';
	}
	if(usedStock.value < 0 && !delDivObj.checked){
		usedStock.style.backgroundColor = 'pink';
	}
	var uploadFile = document.getElementById("uploadFile");
	
	uploadFile.style.backgroundColor = 'white';
	
	if(!fileCheck()){
		uploadFile.style.backgroundColor = 'pink';
	}
	//入力チェック-------------------------------------------------------------------------end
}
//「登録」実行
//引数1:btnCate=1:登録 2:編集 3:
function orderBtnExe(btnCate){
	mainForm = document.getElementById("F1");

	var itemNo ="";

	//変更以外
	<%if(!"2".equals(strOutputCate)){ %>
		itemNo = document.getElementById("itemNo").value; 		
	<%}%>


	var delDivObj  =  document.getElementById("delDiv");  		//削除フラグ
	var cntDiv = document.getElementById("cntDiv").value; 			//カウント品可否
	var itemNm = document.getElementById("itemNm").value; 			//品名
	var model = document.getElementById("model").value;				//型式
	var rackNo = document.getElementById("rackNo").value;			//棚番
	var unitPrice  =  document.getElementById("unitPrice").value;  	//単価
	var leadTm  =  document.getElementById("leadTm").value;  		//リードタイム
	var machineNo = document.getElementById("machineNo").value;		//設備機番
	
	var basicStock  =  document.getElementById("basicStock").value;	//基準在庫
	var odrLot  =  document.getElementById("odrLot").value;  		//発注単位
	var odrPoint  =  document.getElementById("odrPoint").value;  	//発注点
	var newStock  =  document.getElementById("newStock").value;  	//新品在庫数
	var usedStock  =  document.getElementById("usedStock").value;  	//中古在庫数
	var upReason  =  document.getElementById("upReason").value;  	//変更理由

	
	//入力チェック-----------------------------------------------------------------start
	if(itemNo =="" && btnCate !="2"){
		alert_Custom("<%=Message.getMessage("WRN00010").replace("$1", "Y品番")%>");
		return ;
	}
	//新規時のみ
	if(btnCate =="1"){
		//予備品Mから存在チェック
		if(!mRsvSupplyCheck(btnCate)){
			return ;
		}
	}
	if(!itemNo.match(/^Y[0-9]{4}-[0-9]{5}$/) && btnCate !="2"){
		alert_Custom("<%=Message.getMessage("WRN01180")%>");
		return ;
	}else if(delDivObj.checked <%if(!"inv3100".equals(strDisplayCate)){%>&& btnCate !="2"<%}%>){
		alert_Custom("<%=Message.getMessage("WRN00140")%>");
		return ;
	}
	if(cntDiv ==""){
		alert_Custom("<%=Message.getMessage("WRN00010").replace("$1", "カウント可否")%>");
		return ;
	}else if(itemNm ==""){
		alert_Custom("<%=Message.getMessage("WRN00010").replace("$1", "品名")%>");
		return ;
	}else if(itemNm.length > ITEMNM_MODEL_MAXLENGTH){
		alert_Custom("<%=Message.getMessage("WRN01580").replace("$1", "品名").replace("$2","100")%>");
		return ;
	}else if(model ==""){
		alert_Custom("<%=Message.getMessage("WRN00010").replace("$1", "型式")%>");
		return ;
	}else if(model.length > ITEMNM_MODEL_MAXLENGTH){
		alert_Custom("<%=Message.getMessage("WRN01580").replace("$1", "型式").replace("$2","100")%>");
		return ;
	}else if(rackNo =="" && !delDivObj.checked){
		alert_Custom("<%=Message.getMessage("WRN00010").replace("$1", "棚番")%>");
		return ;
	}
	
	if(rackNo !="" && !delDivObj.checked){
		//予備品Mから棚番の存在チェック
		if(!mRsvSupplyCheckRackNo(btnCate)){
			return ;
		}
	}
	
	if(machineNo ==""){
		alert_Custom("<%=Message.getMessage("WRN00010").replace("$1", "設備機番")%>");
		return ;
	}
	if(!fileCheck()){
		alert_Custom("<%=Message.getMessage("WRN01590").replace("$1", "画像ファイル").replace("$2","jpg,png,gif")%>");
		return ;
	}
	if(unitPrice ==""){
		alert_Custom("<%=Message.getMessage("WRN00010").replace("$1", "単価")%>");
		return ;
	}else if(unitPrice < 1){
		alert_Custom("<%=Message.getMessage("WRN00061").replace("$1", "単価")%>");
		return ;
	}else if(leadTm ==""){
		alert_Custom("<%=Message.getMessage("WRN00010").replace("$1", "L/T")%>");
		return ;
	}else if(leadTm < 0){
		alert_Custom("<%=Message.getMessage("WRN00060").replace("$1", "L/T")%>");
		return ;
	}else if(basicStock ==""){
		alert_Custom("<%=Message.getMessage("WRN00010").replace("$1", "基準在庫")%>");
		return ;
	}else if(basicStock < 1){
		alert_Custom("<%=Message.getMessage("WRN00061").replace("$1", "基準在庫")%>");
		return ;
	}else if(odrLot ==""){
		alert_Custom("<%=Message.getMessage("WRN00010").replace("$1", "発注単位")%>");
		return ;
	}else if(odrLot < 1){
		alert_Custom("<%=Message.getMessage("WRN00061").replace("$1", "発注単位")%>");
		return ;
	}else if(newStock =="" && !delDivObj.checked){
		alert_Custom("<%=Message.getMessage("WRN00010").replace("$1", "新品在庫")%>");
		return ;
	}else if(newStock < 0 && !delDivObj.checked){
		alert_Custom("<%=Message.getMessage("WRN00060").replace("$1", "新品在庫")%>");
		return ;
	}else if(odrPoint ==""){
		alert_Custom("<%=Message.getMessage("WRN00010").replace("$1", "発注点")%>");
		return ;
	}else if(odrPoint < 0){
		alert_Custom("<%=Message.getMessage("WRN00060").replace("$1", "発注点")%>");
		return ;
	}else if(usedStock =="" && !delDivObj.checked){
		alert_Custom("<%=Message.getMessage("WRN00010").replace("$1", "中古在庫")%>");
		return ;
	}else if(usedStock < 0 && !delDivObj.checked){
		alert_Custom("<%=Message.getMessage("WRN00060").replace("$1", "中古在庫")%>");
		return ;
	}else if(upReason ==""){
		alert_Custom("<%=Message.getMessage("WRN00010").replace("$1", "メンテ理由")%>");
		return ;
	//入力チェック-----------------------------------------------------------------end
	}else{
		if(btnCate=="1"){
			var afterFunc="yesOrderBtn();";
			if (!confirm_Custom3("<%=Message.getMessage("INF01060").replace("$1","直結看板予備品情報")%>",afterFunc)){
				return ;
			}
		}else if(btnCate=="2"){
			//削除がクリックされていれば追加チェック
			if(delDivObj.checked){
				mRsvSupplyCheckZaiko(btnCate);
			}else{
				var afterFunc="yesUpdateBtn();";
				if (!confirm_Custom3("<%=Message.getMessage("INF01070").replace("$1","直結看板予備品情報")%>",afterFunc)){
					return ;
				}
			}
		}
		
	}
}

//「はい」を押された時
function yesOrderBtn(){
	document.getElementById("orderExe").value = "1";
	mainForm = document.getElementById("F1");
	mainForm.submit();
}

//「はい」を押された時
function yesUpdateBtn(){
	document.getElementById("updateExe").value = "1";
	mainForm = document.getElementById("F1");
	mainForm.submit();
}

//*************************************************
//AJAX 部分(削除がクリックされていれば追加チェック)
//削除の時は新品在庫＞0、又は中古在庫＞0のときは、確認メッセージを表示する。
//※※編集時のみ※※
//*************************************************

//「はい」を押された時
function yesUpdateBtn2(btnCate){
	document.getElementById("updateExe").value = "1";
	mainForm = document.getElementById("F1");
	mainForm.submit();
}
function yesUpdateBtn3(btnCate){
	var afterFunc="yesUpdateBtn2('"+btnCate+"');";
	if (!confirm_Custom3("<%=Message.getMessage("INF01070").replace("$1","直結看板予備品情報")%>",afterFunc)){
		return ;
	}
}
function mRsvSupplyCheckZaiko(btnCate){
	
	var findItemNo = document.getElementById("keyItemNo").value;
	
	var xmlHttp;

	xmlHttp = new XMLHttpRequest();
	xmlHttp.onreadystatechange = checkStatus2;
	xmlHttp.open("GET", "../itm2099/itm2099?itemCd="+findItemNo, false);
	xmlHttp.send(null);

	function checkStatus2(){
		if (xmlHttp.readyState == 4 && xmlHttp.status == 200){
			var xml = xmlHttp.responseXML;
			var rootNodes = xml.getElementsByTagName("list");
			var rootNode = rootNodes[0];
			var json = JSONConvert(rootNode);
			if (json==null) {
			}else {
				var newStock = json.newstock;
				var useStock = json.usestock;
				
				var rackNo = document.getElementById("rackNo").value;			//棚番
				var newStockValue  =  document.getElementById("newStock").value;  	//新品在庫数
				var usedStockValue  =  document.getElementById("usedStock").value;  	//中古在庫数
				//新品在庫＞0、又は中古在庫＞0のときは、確認メッセージを表示する。
				if(newStock>0 || useStock>0 || rackNo!="" || newStockValue!="" || usedStockValue!=""){
					if(btnCate=="3"){
						var afterFunc="yesItemChangeBtn2('"+btnCate+"');";
						if (!confirm_Custom3("<%=Message.getMessage("INF01190")%>",afterFunc)){
							return ;
						}
					}else{
						var afterFunc="yesUpdateBtn3('"+btnCate+"');";
						if (!confirm_Custom3("<%=Message.getMessage("INF01090")%>",afterFunc)){
							return ;
						}
					}
				}else{
					if(btnCate=="3"){
						var afterFunc="yesItemChangeBtn('"+btnCate+"');";
						if (!confirm_Custom3("<%=Message.getMessage("INF01170").replace("$1","直結看板以外予備品情報")%>",afterFunc)){
							return ;
						}
					}else{
						var afterFunc="yesUpdateBtn2('"+btnCate+"');";
						if (!confirm_Custom3("<%=Message.getMessage("INF01070").replace("$1","直結看板予備品情報")%>",afterFunc)){
							return ;
						}
					}
				}
			}
		}
	}
}


function JSONConvert(node){
	var type = node.nodeType;
	if ( isTextNode(node) ){
		var text = getTextValue(node);
		return text;
	}
	if ( type==1 ){
		var json = {};
		var nodeName = node.nodeName;
		var childs = node.childNodes;

		for (var i = 0; i<childs.length; i++){
			var child = childs[i];
			var obj = json[child.nodeName];

			if ( child.nodeType == 1 ){
				if ( obj ){
					var array = null;
					if ( !isArray(obj) ){
						array=[];
						array[array.length]=obj;
					}else{
						array=json[child.nodeName];
					}
					array[array.length]=JSONConvert(child);
					json[child.nodeName]=array;
				}else{
					json[child.nodeName]=JSONConvert(child);
				}
			}
		}
		return json;
	}
}

function isTextNode(node){
	if ( node.hasChildNodes() ){
		var childs = node.childNodes;
		for (var i = 0; i<childs.length; i++){
			var child = childs[i];
			if ( child.nodeType != 3 ) return false;
		}
	}
	return true;
}

function getTextValue(node){
	if ( node.hasChildNodes() ){
		var childs = node.childNodes;
		var child = childs[0];
		if ( child.nodeType == 3 ){
			return child.nodeValue;
		}
	}
	return null;
}
//------------------------------------------------------------------------------

//*************************************************
//AJAX 部分(予備品Mから存在チェック)
//*************************************************
function mRsvSupplyCheck(btnCate){
	
	
	var findOdrNo = document.getElementById("itemNo").value;

	xmlHttp = new XMLHttpRequest();
	//xmlHttp.onreadystatechange = checkStatus2;
	xmlHttp.open("GET", "../itm2099/itm2099?itemCd="+findOdrNo, false);
	xmlHttp.send(null);

	//if (xmlHttp.status == 200){
	if (xmlHttp.readyState == 4 && xmlHttp.status == 200){
		var xml = xmlHttp.responseXML;
		var rootNodes = xml.getElementsByTagName("list");
		var rootNode = rootNodes[0];
		var json = JSONConvert(rootNode);
		
		if (json==null) {
			//(IEの時対策)
			return true;
		}else {
			var itemNo1 = json.itemcd1;
			
			//存在チェック
			if(!itemNo1){
				//無し
				//mRsvSupplyCheckRackNo(btnCate); //出庫実行
				return true;
			}else{
				//有り
				//予備品として既に登録済みの品番です。
				alert_Custom("<%=Message.getMessage("WRN00130")%>");
				
				return false;
			}

		}
	}
	return false;
}

//*************************************************
//AJAX 部分(予備品Mから棚番の存在チェック)
//*************************************************
function mRsvSupplyCheckRackNo(btnCate){
	
	var findRackNo = document.getElementById("rackNo").value;
	var findKeyItemNo = document.getElementById("keyItemNo").value;
	
	var xmlHttp;

	xmlHttp = new XMLHttpRequest();
	//xmlHttp.onreadystatechange = checkStatus2;
	xmlHttp.open("GET", "../spa2001/spa2001?rackNo="+findRackNo+"&itemNo="+findKeyItemNo, false);
	xmlHttp.send(null);

	if (xmlHttp.readyState == 4 && xmlHttp.status == 200){
		var xml = xmlHttp.responseXML;
		var rootNodes = xml.getElementsByTagName("list");
		var rootNode = rootNodes[0];
		var json = JSONConvert(rootNode);
		
		if (json==null) {
			//(IEの時対策)
			return true;
		}else {
			var rackNoExitFlg = json.rackNoExitFlg;
			
			//存在チェック
			if(!rackNoExitFlg){
				//無し
				//orderBtnExe(btnCate); //出庫実行
				return true;
			}else{
				//有り
				alert_Custom("<%=Message.getMessage("WRN00090").replace("$1","棚番")%>");
				return false;
			}

		}
	}
	return false;
}


//*************************************************
//AJAX 部分(確定時と発注時の予備品Mの更新日を比較)
//※※編集時のみ※※
//*************************************************
function updateDtCheck(btnCate){
	
	var findItemNo = document.getElementById("keyItemNo").value;
	
	var xmlHttp;

	xmlHttp = new XMLHttpRequest();
	xmlHttp.onreadystatechange = checkStatus2;
	xmlHttp.open("GET", "../itm2099/itm2099?itemCd="+findItemNo, false);
	xmlHttp.send(null);

	function checkStatus2(){
		if (xmlHttp.readyState == 4 && xmlHttp.status == 200){
			var xml = xmlHttp.responseXML;
			var rootNodes = xml.getElementsByTagName("list");
			var rootNode = rootNodes[0];
			var json = JSONConvert(rootNode);
			if (json==null) {
			}else {
				var orderUpdateDt = json.updatedt;
				var confirmUdateDt = document.getElementById("updateDt_hid").value;
				var stockUpdateDt = json.stockupdate; //在庫更新日（発注）
				var confirmUdateStock = document.getElementById("updateDt_stock").value; //在庫更新日
				var newStock = json.newstock;
				var useStock = json.usestock;
				//確定時と発注時の更新日を比較
				if((orderUpdateDt == confirmUdateDt) && (stockUpdateDt == confirmUdateStock)){
					if(btnCate=="3"){
						itemChangeBtnExe(btnCate);
					}else{
						orderBtnExe(btnCate);
					}
					
				}else{

					alert_Custom("<%=Message.getMessage("WRN01150").replace("$1", "予備品のマスタ情報").replace("$2", "予備品")%>");
					//予備品のマスタ情報が既に変更されています。発注を再度やり直して下さい。
					return;
				}

			}
		}
	}
}


//*************************************************
//AJAX 部分(発注Tと修理貸出Tから存在チェックし削除可能かチェック)
//※※編集時のみ※※
//*************************************************
function mRsvSupplyCheckDelete(btnCate){
	
	var findOdrNo = document.getElementById("keyItemNo").value;
	
	var xmlHttp;

	xmlHttp = new XMLHttpRequest();
	xmlHttp.onreadystatechange = checkStatus2;
	xmlHttp.open("GET", "../spa2002/spa2002?itemNo="+findOdrNo, false);
	xmlHttp.send(null);

	function checkStatus2(){
		if (xmlHttp.readyState == 4 && xmlHttp.status == 200){
			var xml = xmlHttp.responseXML;
			var rootNodes = xml.getElementsByTagName("list");
			var rootNode = rootNodes[0];
			var json = JSONConvert(rootNode);
			
			if (json==null) {
			}else {
				var deleteExistFlg = json.deleteExistFlg;
				
				//存在チェック
				if(!deleteExistFlg){
					//無し
					updateDtCheck(btnCate);
					
				}else{
					//有り
					if(btnCate=="3"){
						//Y品番は現在仕掛中であるため、直結看板以外予備品への移動登録ができません。　
						alert_Custom("<%=Message.getMessage("WRN01120")%>");
					}else{
						//Y品番は現在仕掛中であるため、削除できません。
						alert_Custom("<%=Message.getMessage("WRN01110")%>");
					}
					return;
				}

			}
		}
	}
}

//予備品メンテ理由にセット
function setUpReason(){

	var UpReasonSel = document.getElementById("upReasonSelect");
	var UpReason = document.getElementById("upReason");

	UpReason.value = UpReasonSel.options[UpReasonSel.selectedIndex].text;
}

//削除チェックボックスにチェックが入った時＆初期表示の処理
function delDivChange(){
	var delDivObj = document.getElementById("delDiv");
	var rackNo = document.getElementById("rackNo");
	var rackNoTxt = document.getElementById("rackNoTxt");
	var usedStock = document.getElementById("usedStock");
	var newStock = document.getElementById("newStock");
	
	if(delDivObj.checked){
		rackNo.disabled=true;
		usedStock.disabled=true;
		newStock.disabled=true;
		//rackNo.value="";
		//usedStock.value="";
		//newStock.value="";
		rackNo.style.backgroundColor="#CCC";
		rackNoTxt.style.backgroundColor="#CCC";
		usedStock.style.backgroundColor="#CCC";
		newStock.style.backgroundColor="#CCC";
	}else{
		rackNo.disabled=false;
		usedStock.disabled=false;
		newStock.disabled=false;
		rackNo.style.backgroundColor="white";
		rackNoTxt.style.backgroundColor="white";
		usedStock.style.backgroundColor="white";
		newStock.style.backgroundColor="white";
	}
	
}

//数字しか入力できないように
function numberKeyPress(){
	//備考：少数点とかマイナスを入力させるには48ではなく45かな？
	if ((event.keyCode < 48) || (event.keyCode > 57)){event.returnValue = false;};
}

function fileCheck(){
	var obj = document.getElementById("uploadFile");
	var target = obj.value;
	if(!target){
		return true;
	}
	imgList = new Array("jpg", "png", "gif", "jpeg");
	
	var okFlg = false;
	for(i=0;i<imgList.length;i++){
		var str = target;
		var endStr = getExtention(str);
		if(endStr){
			if (endStr.toLowerCase() === imgList[i]){
				okFlg = true;
			}
		}
	}
	if(!okFlg){
		return false;
	}else{
		return true;
	}
}
//拡張子を取得する
function getExtention(fileName) {
	var ret;
	if (!fileName) {
		return ret;
	}
	var fileTypes = fileName.split(".");
	var len = fileTypes.length;
	if (len === 0) {
		return ret;
	}
	ret = fileTypes[len - 1];
	return ret;
}

//3桁カンマ区切り
function addFigure(obj) {
	
	str = obj.value;
	var num = new String(str).replace(/,/g, "");

	while(num != (num = num.replace(/^(-?\d+)(\d{3})/, "$1,$2")));

	obj.value = num;

}

// カンマ除去
function delComma(w) {
    var z = w.replace(/,/g,"");
    return (z);
}

// カンマ除去
function delComma2(obj) {
	str = obj.value;
	
	var num = new String(str).replace(/,/g, "");
	
	obj.value = num;
	
}


//イメージファイルエラー時
function imgCheck(){

	var imageItem = document.getElementById("imageItem");
	
	imageItem.src="../../img/blank.gif";
	

}
</script>

	</head>

	<body onLoad="onInit()" style="margin: 0px 4px 0px 0px;">
		<form class="frmMain" name="main" id="F1" action="./spa2000" method="post" enctype="multipart/form-data" onsubmit="return false;">
			<table class="tblMain" width="100%" cellspacing="0" cellpadding="0" border="0">
				<tr>
					<td valign="top">
						<table class='main-width-tb'  cellspacing='0' cellpadding='0' border='0'><tr><td></td></tr></table>
						<table class='main-height-tb' cellspacing='0' cellpadding='0' border='0'><tr><td></td></tr></table>

						<!-- Header Menu START -->
						<div class="header-title">予備品管理システム(<%=formBean.kojou%>)</div>
						<!-- Header Menu END -->

						<!-- ***** [FORM] MAIN-FORM ***** -->
						<div id="lc-out" style="z-index: 0;">
							<div id="lc-in" style="z-index: 0">
<%
//題名の設定
String headSubName="新規";
if("2".equals(strOutputCate) || "inv3100".equals(strDisplayCate)){
	headSubName = "変更";
}

%>
								<div  style="margin: 20px ; width: 98%;">
									<div class="subtitle">直結看板予備品情報メンテナンス画面（<%=headSubName%>）</div>
									<table  border="0" width="98%">
										<tr>
											<td>
												<table border="0" style="margin-left: 30px; width: 950px;" align="left">
													<tr>
														<td>
															Y品番：
														</td>
														<td>
															<%if("2".equals(strOutputCate) || "inv3100".equals(strDisplayCate)){ %>
																<input type="text"  class="ReadStyle" name="itemNo1" id="itemNo1" style="width: 52px;"  value="<%=formBean.getItemNo1() %>" readonly> -
																<input type="text"  class="ReadStyle" name="itemNo2" id="itemNo2" style="width: 52px;"  value="<%=formBean.getItemNo2() %>" readonly>
																<%if("inv3100".equals(strDisplayCate)){%>
																	<input type="hidden"  class="" name="itemNo" id="itemNo" value="<%=formBean.getItemNo1()%>-<%=formBean.getItemNo2()%>">
																<%} %>
															<%}else{ %>
																<input type="text"  class="txtmode3" name="itemNo" id="itemNo" style="width: 120px;"  value="<%=formBean.getItemNo() %>" onkeyup="itemNoKeyUp(this)" maxlength="11">
															<%} %>
														</td>
														<td >
															カウント可否：
														</td>
														<td>
															<select name="cntDiv"  id="cntDiv"  style="width:160px;" onChange="">
																	<%
																	String[] outSelect = {"",""};
																	if("0".equals(formBean.getCntDiv())){
																		outSelect[1] = "selected";
																	}else{
																		outSelect[0] = "selected";
																	}
																	%>
																	<option value='1' <%=outSelect[0]%>>カウント品</option>
																	<option value='0' <%=outSelect[1]%>>実勘省略品</option>
															</select>
														</td>
														<td>
															<div style="color:red;<%if("1".equals(strOutputCate)){ %>display:none<%} %>">
															削　除：
															</div>
														</td>
														<td>
															<input type="checkbox"  class="" name="delDiv" id="delDiv" style="width: 42px; height:25px;<%if("1".equals(strOutputCate)){ %>display:none<%} %>"  value="1"<%=("1".equals(formBean.getDelDiv()) ? "checked":"") %> onclick="delDivChange();">
														</td>
													</tr>
													<!-- スペース -->
													<tr style="height: 30px;"><td></td></tr>
													<tr>
														<td>
															品　名：
														</td>
														<td colspan="5">
															<textarea name="itemNm" id="itemNm" class="txtmode1" cols="40" rows="2" style="width:  870px;" maxlength="100"><%=formBean.getItemNm() %></textarea>
														</td>
													</tr>
													<!-- スペース -->
													<tr style="height: 30px;"><td></td></tr>
													<tr>
														<td>
															型　式：
														</td>
														<td colspan="5">
															<textarea name="model" id="model" class="txtmode1" cols="40" rows="2" style="width:  870px;" maxlength="100"><%=formBean.getModel() %></textarea>
														</td>
													</tr>
												</table>

												<table  border="0" style="width: 310;" align="left">
													<tr>
														<td>
															<img border="0	" style="max-height:170px; max-width:300px; height :auto;  width :300px;" name="imageItem" id="imageItem" src="<%=appMng.getAppConfig("userconfig.imagepath")%><%=formBean.getPicfileNm() %>?<%=imageTime %>"  onError="imgCheck()";   width="300px" height="150px" alt="画像" title="画像">
														</td>
													</tr>
												</table>
											</td>
										</tr>
									</table>

									<!-- スペース -->
									<table height="30px" width="98%"><tr><td></td></tr></table>

									<table  border="0"  width="98%" id="addTable">
										<tr>
											<td>
												<table border="0" style="margin-left: 30px; width: 98%;">
													<tr>
														<td>
															棚　番：
														</td>
														<td>
															<!-- 
															<input type="text"  class="" name="rackNo" id="rackNo" style="width: 100px; "  value="<%=formBean.getRackNo() %>" maxlength="8">
															 -->
															<%
															String rackNo = "";
															Spa2000Bean.PullData[] inputTanaList = formBean.getInputTanaList();
															for (int i = 0; inputTanaList != null && i < inputTanaList.length; i++) {
																Spa2000Bean.PullData data = inputTanaList[i];
																if(data.key.equals(formBean.getRackNo())){
																	rackNo = data.value;
																}
															}
															%>
															<input type="hidden" name="rackNo" id="rackNo" value="<%=formBean.getRackNo()%>" >
															<input type="text" class="rackNo inputStyle" style="width:100px;" name="rackNoTxt" id="rackNoTxt" value="<%=rackNo%>" maxlength="8"><br>
														</td>
														<td >
															設備機番：
														</td>
														<td>
															<%
															String machineNo = "";
															Spa2000Bean.PullData[] inputMachineNoList = formBean.getInputMachineNoList();
															for (int i = 0; inputMachineNoList != null && i < inputMachineNoList.length; i++) {
																Spa2000Bean.PullData data = inputMachineNoList[i];
																if(data.key.equals(formBean.getMachineNo())){
																	machineNo = data.value;
																}
															}
															%>
															<input type="hidden" name="machineNo" id="machineNo" value="<%=formBean.getMachineNo()%>" >
															<input type="text" class="machineNo inputStyle" style="width:350px;" name="machineNoTxt" id="machineNoTxt" value="<%=machineNo%>" maxlength="100"><br>
														</td>
														<td >
															画像ファイル：
														</td>
														<td colspan="2">
															<input type="file" name="uploadFile" id="uploadFile"/>
															<input type="hidden" id="picfileNm" name="picfileNm" value="<%=formBean.getPicfileNm() %>">
														</td>
														<td>
															&nbsp;
														</td>
													</tr>
													<!-- スペース -->
													<tr style="height: 30px;"><td></td></tr>
													<tr>
														<td>
															単　価：
														</td>
														<td>
															<input type="text"  class="txtmode3" name="unitPrice" id="unitPrice" style="width: 120px; text-align:right;"  value="<%=formBean.getUnitPrice() %>" onKeyPress="numberKeyPress();" maxlength="8" onfocus="delComma2(this);" onblur="addFigure(this);">
														</td>
														<td >
															仕入先：
														</td>
														<td>
															<select name="supplier"  id="supplier"  style="width:350px;" onChange="">
																	<option value=''selected></option>
																	<%
																	Spa2000Bean.PullData[] nputSupplierList = formBean.getInputSupplierList();
																	for (int i = 0; nputSupplierList != null && i < nputSupplierList.length; i++) {
																		Spa2000Bean.PullData data = nputSupplierList[i];
																		if(data.key.equals(formBean.getSupplier())){
																			data.selected = "selected";
																		}
																	%>
																	<option value='<%=data.key%>' <%=data.selected%> ><%=data.value%></option>
																	<%}%>
															</select>
														</td>
													</tr>
													<!-- スペース -->
													<tr style="height: 30px;"><td></td></tr>
													<tr>
														<td>
															L/T：
														</td>
														<td>
															<input type="text"  class="txtmode3" name="leadTm" id="leadTm" style="width:120px; text-align:right;"  value="<%=formBean.getLeadTm() %>" onKeyPress="numberKeyPress();" maxlength="3">
														</td>
														<td >
															部品メーカー：
														</td>
														<td>
															<select name="partsMaker"  id="partsMaker"  style="width:350px;" onChange="">
																	<option value=''selected></option>
																	<%
																	Spa2000Bean.PullData[] inputPartsMakerList = formBean.getInputPartsMakerList();
																	for (int i = 0; inputPartsMakerList != null && i < inputPartsMakerList.length; i++) {
																		Spa2000Bean.PullData data = inputPartsMakerList[i];
																		if(data.key.equals(formBean.getPartsMaker())){
																			data.selected = "selected";
																		}
																	%>
																	<option value='<%=data.key%>' <%=data.selected%> ><%=data.value%></option>
																	<%}%>
															</select>
														</td>
													</tr>
												</table>
											</td>
										</tr>
									</table>

									<!-- スペース -->
									<table height="30px" width="98%"><tr><td></td></tr></table>
									<table height="30px" width="98%" class="borderTop"><tr><td></td></tr></table>

									<table  border="0"  width="98%">
										<tr>
											<td>
												<table border="0" style="margin-left: 30px; width: 98%;">
													<tr>
														<td>
															基準在庫：
														</td>
														<td>
															<input type="text"  class="txtmode3" name="basicStock" id="basicStock" style="width: 120px; text-align:right;"  value="<%=formBean.getBasicStock() %>" onKeyPress="numberKeyPress();" maxlength="3">
														</td>
														<td >
															発注単位：
														</td>
														<td>
															<input type="text"  class="txtmode3" name="odrLot" id="odrLot" style="width: 120px; text-align:right;"  value="<%=formBean.getOdrLot() %>" onKeyPress="numberKeyPress();" maxlength="3">
														</td>
														<td >
															新品在庫：
														</td>
														<td>
															<input type="text"  class="txtmode3" name="newStock" id="newStock" style="width: 120px;text-align:right;"  value="<%=formBean.getNewStock() %>" onKeyPress="numberKeyPress();" maxlength="5" onfocus="delComma2(this);" onblur="addFigure(this);">
														</td>
													</tr>
													<!-- スペース -->
													<tr style="height: 30px;"><td></td></tr>
													<tr>
														<td></td>
														<td></td>
														<td >
															発注点：
														</td>
														<td>
															<input type="text"  class="txtmode3" name="odrPoint" id="odrPoint" style="width: 120px; text-align:right;"  value="<%=formBean.getOdrPoint() %>" onKeyPress="numberKeyPress();" maxlength="3">
														</td>
														<td >
															中古在庫：
														</td>
														<td>
															<input type="text"  class="txtmode3" name="usedStock" id="usedStock" style="width: 120px; text-align:right;"  value="<%=formBean.getUsedStock() %>" onKeyPress="numberKeyPress();" maxlength="5" onfocus="delComma2(this);" onblur="addFigure(this);">
														</td>
													</tr>
												</table>
											</td>
										</tr>
									</table>

									<!-- スペース -->
									<table height="30px" width="98%"><tr><td></td></tr></table>
									<table height="30px" width="98%" class="borderTop"><tr><td></td></tr></table>

									<table  border="0" width="98%">
										<tr>
											<td>
												<table border="0" style="margin-left: 30px; width: 98%;" align="left">
													<tr>
														<td>
															メンテ理由：
														</td>
														<td colspan="5">
															<input type="text"  class="txtmode1" name="upReason" id="upReason" style="width: 500px;"  value="">
															<select name="upReasonSelect"  id="upReasonSelect"  style="width:220px;" onChange="setUpReason();">
																	<option value=''selected></option>
																	<%
																	Spa2000Bean.PullData[] inputUpReasonList = null;
																	if("2".equals(strOutputCate)){
																		inputUpReasonList = formBean.getInputUpReasonList_u();
																	}else{
																		inputUpReasonList = formBean.getInputUpReasonList_i();
																	}
																	for (int i = 0; inputUpReasonList != null && i < inputUpReasonList.length; i++) {
																		Spa2000Bean.PullData data = inputUpReasonList[i];
																	%>
																	<option value='<%=data.key%>' <%=data.selected%> ><%=data.value%></option>
																	<%}%>
															</select>
														</td>
													</tr>
													<tr>
														<td colspan="6" align=center>　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　
<%
//題名の設定
String buttonName="../../common/img/pc/btn_insert_off.png";
if("2".equals(strOutputCate) || "inv3100".equals(strDisplayCate)){
	buttonName = "../../common/img/pc/btn_update_off.png";
}
%>
<%if("2".equals(strOutputCate)){ %>
															<input type="image" src="../../common/img/pc/btn_tyokketsuigai_insert_off.png" onclick="itemChangeBtn();" class="confirmBtn"  value="戻る">
<%} %>
															&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;　　
															<%if("2".equals(strOutputCate)){ %>
																<input type="image" src="<%=buttonName %>" onclick="updateBtn();" class="confirmBtn2" value="">　　
															<%}else{ %>
																<input type="image" src="<%=buttonName %>" onclick="orderBtn();" class="confirmBtn2" value="">　　
															<%} %>
															&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
															<input type="image" src="../../common/img/pc/btn_back_off.png" onclick="backBtn('spa1000');" class="confirmBtn"  value="戻る">　
														</td>
													</tr>
												</table>
											</td>
										</tr>
									</table>

								</div>
							</div><!-- lc-in End -->


							<!-- ログ Start -->
							<!-- ログ End -->

						</div><!-- lc-out  -->
					</td>
				</tr>
			</table>

			<input type="hidden" name="cmd" value="cmd01">
			
			<input type="hidden" id="nextPage" name="nextPage" value="">
			<input type="hidden" id="orderExe" name="orderExe" value="">
			<input type="hidden" id="updateExe" name="updateExe" value="">
			<input type="hidden" id="itemChangeExe" name="itemChangeExe" value="">
			<input type="hidden" id="stateFlg" name="stateFlg" value="">
			
			<input type="hidden" id="keyItemNo" name="keyItemNo" value="<%=formBean.getKeyItemNo() %>">
			<input type="hidden" id="outputCate" name="outputCate" value="<%=formBean.getOutputCate() %>">
			<input type="hidden" id="updateDt_hid" name="updateDt_hid" value="<%=formBean.getUpdateDt_hid() %>">
			<input type="hidden" id="updateDt_stock" name="updateDt_stock" value="<%=formBean.getUpdateDt_stock() %>">
			
			<input type="hidden" id="displayCate" name="displayCate" value="<%=formBean.getDisplayCate() %>">
			<!-- 履歴用 -->
			<input type="hidden" id="unitPriceOld" name="unitPriceOld" value="<%=formBean.getUnitPriceOld() %>">
			<input type="hidden" id="basicStockOld" name="basicStockOld" value="<%=formBean.getBasicStockOld() %>">
			<input type="hidden" id="odrLotOld" name="odrLotOld" value="<%=formBean.getOdrLotOld() %>">
			<input type="hidden" id="odrPointOld" name="odrPointOld" value="<%=formBean.getOdrPointOld() %>">
			<input type="hidden" id="newStockOld" name="newStockOld" value="<%=formBean.getNewStockOld() %>">
			<input type="hidden" id="usedStockOld" name="usedStockOld" value="<%=formBean.getUsedStockOld() %>">
			

<!-- RACKNO-DROPDOWN START -->
<div class="dropdown-panel" id="dropdown-panel2">
	<div class="dropdown-panel-in">
		<div class="header">
			<div style="float:left;width:100px;height:20px;">
				<table border=0>
					<tr>
						<td style="width:100px;height:20px;">棚番</td>
					</tr>
				</table>
			</div>
			<div style="float:right;width:40px;text-align:right;">
				<button class="closebtn" type="button" onClick="closeBtn2();" style="width:18px;height:17px; padding:0px;">
					<img src="../../common/js/dropdown/close.gif" alt="閉じる">
				</button>
			</div>
		</div>
		<div class="drop-contents" id="drop-contents2">
		</div>
		<div class="footer"></div>
	</div>
</div>
<!-- RACKNO-DROPDOWN END -->

<!-- MACHINE-DROPDOWN START -->
<div class="dropdown-panel" id="dropdown-panel3">
	<div class="dropdown-panel-in">
		<div class="header">
			<div style="float:left;width:100px;height:20px;">
				<table border=0>
					<tr>
						<td style="width:100px;height:20px;">設備機番</td>
					</tr>
				</table>
			</div>
			<div style="float:right;width:40px;text-align:right;">
				<button class="closebtn" type="button" onClick="closeBtn3();" style="width:18px;height:17px; padding:0px;">
					<img src="../../common/js/dropdown/close.gif" alt="閉じる">
				</button>
			</div>
		</div>
		<div class="drop-contents" id="drop-contents3">
		</div>
		<div class="footer"></div>
	</div>
</div>
<!-- MACHINE-DROPDOWN END -->

			<!--警告 ポップアップ---------------------------------------------------------------------------- -->
			<div id="allbackgr" class="allbackgr" style="display:none;"></div>
			<div class="opAlertBtn" id = "opAlertBtn" style="display:none;" ></div>
			<div class="opAlertButton" id = "opAlertButton" style="display:none;" ></div>
			<div class="opAlertTop" id = "opAlertTop" style="display:none; font-size:22px;">　予備品管理システム　</div>
			<div class="opAlert" id = "opAlert" style="display:none;"></div>
			<!-- -------------------------------------------------------------------------------------------- -->
		</form>
	</body>
</html>
